Questions
25 of 50
1What is a pseudo-class in CSS?
2How are pseudo-classes different from pseudo-elements?
3What is the syntax of a pseudo-class in CSS?
4Give some commonly used pseudo-classes.
5What does the :hover pseudo-class do?
6What’s the purpose of the :active pseudo-class?
7How does the :visited pseudo-class work for links?
8What is the :focus pseudo-class used for?
9What does the :checked pseudo-class do?
10How does the :disabled pseudo-class behave?
11What is the difference between :first-child and :first-of-type?
12How do :nth-child() and :nth-of-type() differ?
13How do you select every odd or even element using pseudo-classes?
14How can you style an element when it’s being hovered over along with its child?
15What does the :not() pseudo-class do?
16How can you use multiple pseudo-classes together?
17What is the difference between :link and :visited?
18What does the :target pseudo-class represent?
19How can you use :empty to detect empty elements?
20How does the :root pseudo-class differ from the html selector?
21What does the :valid and :invalid pseudo-class do?
22How can you use :required and :optional pseudo-classes in forms?
23What is the use of :in-range and :out-of-range?
24What does :read-only and :read-write do?
25How can you style an input field when it’s autofilled?
26How does the :focus-within pseudo-class work?
27What’s the difference between :focus and :focus-visible?
28What is the purpose of the :placeholder-shown pseudo-class?
29How can you style a checkbox when it is checked or unchecked?
30How can you style invalid form inputs without JavaScript?
31Can pseudo-classes be chained together? Give an example.
32What is the specificity of pseudo-classes compared to normal selectors?
33How can you use :not() effectively to exclude elements from styling?
34How does :has() pseudo-class work, and why is it powerful?
35Is :has() supported in all browsers?
36How does :is() differ from :where() in terms of specificity?
37How can you combine :is() or :where() with other selectors for cleaner code?
38What’s the difference between :nth-child() and :nth-last-child()?
39How can you style only the last element of a list using pseudo-classes?
40What does the :lang() pseudo-class do?
41How do you change a button’s color when hovered but not when disabled?
42How can you highlight the current section in a menu using :target?
43How can you style a form field differently when focused and valid?
44How do you style every third list item differently?
45How can you style alternate table rows without adding extra classes?
46How do you hide empty <p> tags using pseudo-classes?
47How can you style the parent when any child inside it is focused?
48How can you highlight a link only when it’s both focused and hovered?
49How can you style the first letter of only the first paragraph using pseudo-classes?
50How would you use :has() to select a <div> that contains an image?
25 / 50

How can you style an input field when it’s autofilled?

Styling Autofilled Input Fields Using CSS

Browsers often apply special styling to input fields that have been autofilled (e.g., by saved passwords or form data). CSS provides vendor-prefixed pseudo-classes to target these autofilled inputs for consistent styling.

How It Works
  1. 1

    Use :-webkit-autofill to style autofilled inputs in WebKit-based browsers (Chrome, Safari, Edge).

  2. 2

    Combine with other selectors like input or textarea to target specific fields.

  3. 3

    You can adjust background color, text color, font, and even add transitions for smoother visuals.

Example: Styling Autofilled Inputs

In this example, when a user’s browser autofills the email or password field, the background changes to a light teal color and text becomes dark teal, providing a clear visual indication that the field has been autofilled.

Best Practices
  1. 1

    Always use !important for autofill styles to override browser default styles.

  2. 2

    Ensure sufficient contrast for text readability on autofilled fields.

  3. 3

    Combine with :focus or :hover to enhance user interaction.

  4. 4

    Test across multiple browsers, as autofill styling support varies and may require vendor prefixes.

Difficulty: 6/10
Topics: autofill pseudo-classes, browser inconsistency, CSS specificity

Scenario Questions

0-2 years experience
  1. 1

    How would you change the background color of an input field when the browser autofills it with a saved password?

  2. 2

    What happens if you try to style an autofilled input with just input:focus — why doesn’t that work?

  3. 3

    You set background-color: yellow on an input, but it stays white when autofilled — what’s the first thing you’d check?

2-5 years experience
  1. 1

    Our login form’s autofilled inputs look broken in Chrome but fine in Firefox — what’s likely causing this and how would you debug it?

  2. 2

    A designer wants autofilled fields to have a subtle blue tint, but the browser’s default yellow override keeps showing up — how do you fix this without breaking accessibility?

  3. 3

    Why does setting input:-webkit-autofill { color: white } sometimes make the text disappear, and how would you fix it?

5-8 years experience
  1. 1

    We’re building a global form system and need consistent autofill styling across all browsers — what’s your strategy for handling browser inconsistencies without bloating CSS or breaking UX?

  2. 2

    An autofill style we added caused a layout shift on mobile when the keyboard popped up — how would you diagnose and fix this without removing the visual feedback?

  3. 3

    How would you design a CSS architecture that allows teams to override autofill styles safely across multiple components without creating specificity wars?

8+ years experience
  1. 1

    We’re migrating a legacy form system that relies on inline styles for autofill — how would you phase out those styles without breaking user experience or introducing regressions across 20+ countries?

  2. 2

    Autofill styling is causing performance issues on low-end devices during form rendering — how would you architect a solution that balances visual fidelity, performance, and maintainability at scale?

  3. 3

    How would you advocate for a standardized autofill styling policy across engineering teams when different product groups have conflicting design requirements and browser support expectations?

Follow-up Questions

  • What happens if you use background-color: transparent on an autofilled input?
  • Why might your styles work in Chrome but not in Safari?
  • How would you test this across different browsers and devices?